﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Extensions.XElementExtension
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Linq;
using System.Xml.Linq;


namespace LayersParser.Extensions;

public static class XElementExtension
{
  public static XNode CheckingAttributes(this XElement xElement, string attribute)
  {
    XNode xnode = xElement.FirstNode;
    while (xnode != null && !xnode.ToString().Contains(attribute))
      xnode = xnode.NextNode;
    return xnode;
  }

  public static XElement CheckingValue(this XElement xElement, string value, string name)
  {
    foreach (XElement xelement in xElement.Elements((XName) name).ToList<XElement>())
    {
      if (xelement.Value == value)
        return xelement;
    }
    return (XElement) null;
  }

  public static string FirstCDATA(this XElement xElement)
  {
    string[] separator = new string[2]{ "<![CDATA[", "]]>" };
    for (XNode xnode = xElement.FirstNode; xnode != null; xnode = xnode.NextNode)
    {
      if (xnode.ToString().Split(separator, StringSplitOptions.None).Length > 2)
        return xnode.ToString().Split(separator, StringSplitOptions.None)[1];
    }
    return (string) null;
  }
}
